<template>
	<div>
		<el-form ref="form" :model="form" label-width="80px">
			  <el-form-item label="团队名称">
			    <el-input v-model="form.name"></el-input>
			  </el-form-item>
			  <el-form-item label="负责人">
			     <el-select  v-model="form.principal" filterable  @change="changeValue1" placeholder="请选择">
			        <el-option
			          v-for="(value,index) in principal"
			          :key="index"
			          :label="value"
			          :value="value">
			        </el-option>
			      </el-select>
			  </el-form-item>
			  <el-form-item label="QA负责人">
			     <el-select v-model="form.qa" filterable  @change="changeValue2" placeholder="请选择">
			        <el-option
			          v-for="item in qa"
			          :key="item"
			          :label="item"
			          :value="item">
			        </el-option>
			      </el-select>
			  </el-form-item>
			  <el-form-item>
				  <el-button type="primary" icon="el-icon-edit" plain @click="save()">添加</el-button>
				  <el-button type="info" icon="el-icon-delete-solid" plain @click="close()">取消</el-button>
			  </el-form-item>
		</el-form>
		
	</div>
</template>

<script>
import axios from '../../utils/axiosutils.js';
export default {
	name: 'Permission',
	data() {
		return {
			form:{
				name:'',
				principal:[],
				qa:[]
			},
			principal:[],
			qa:[],
			principalname:'',
			qaname:''
		};
	},
	created() {
		this.getData();
	},
	methods:{
		getData(){
			axios.get(
				"/team/principal",
				resp=>{
					
					this.principal=resp.obj.principals;
					this.qa=resp.obj.qa;
				}
			);
		},
		save(){
			axios.post(
				"/team/save",
				resp=>{
					this.$emit('update:show', false);
					this.$emit('getData');
				},
				this.form
			);
			axios.post(
				"/user/addteam",
				resp=>{
					this.$emit('update:show', false);
					this.$emit('getData');
				},{
					principalname:this.principalname,
					qaname:this.qaname,
					teamname:this.form.name
				});
		},
		close(){
			this.$emit('update:show', false);
		},
		changeValue1(data){
			this.principalname=data;
		},
		changeValue2(val){
			this.qaname=val;
		}
	}
};
</script>

<style scoped></style>
